Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 7, 2025

Link issues

fixes #6721

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add comprehensive ModbusFactory documentation to the sample page

Documentation:

  • Explain Modbus RTU and TCP/IP transport modes and their protocol differences
  • Demonstrate IModbusFactory methods to create and remove TCP, UDP, RTU, and RTU-over-TCP/UDP client instances
  • Outline supported Modbus data types (coils, discrete inputs, input registers, holding registers) and corresponding IModbusClient read/write methods

Copilot AI review requested due to automatic review settings September 7, 2025 11:09
@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Sep 7, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 7, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 7, 2025

Reviewer's Guide

This PR enhances the ModbusFactories sample by replacing raw socket code examples with structured ModbusFactory documentation: it introduces protocol overviews, enumerates factory methods for creating/removing clients, details data operation methods, and includes minor formatting and configuration cleanups.

Class diagram for ModbusFactory and related Modbus client types

classDiagram
    class IModbusFactory {
        +GetOrCreateTcpMaster(name, options)
        +GetOrCreateUdpMaster(name, options)
        +GetOrCreateRtuMaster(name, options)
        +GetOrCreateRtuOverTcpMaster(name, options)
        +GetOrCreateRtuOverUdpMaster(name, options)
        +RemoveTcpMaster(name)
        +RemoveUdpMaster(name)
        +RemoveRtuMaster(name)
        +RemoveRtuOverTcpMaster(name)
        +RemoveRtuOverUdpMaster(name)
    }
    class IModbusClient {
        +ReadCoilsAsync()
        +WriteCoilAsync()
        +WriteMultipleCoilsAsync()
        +ReadInputsAsync()
        +ReadInputRegistersAsync()
        +ReadHoldingRegistersAsync()
        +WriteRegisterAsync()
        +WriteMultipleRegistersAsync()
    }
    class IModbusTcpClient {
        <<interface>>
    }
    class IModbusRtuClient {
        <<interface>>
    }
    IModbusFactory --> IModbusTcpClient : creates
    IModbusFactory --> IModbusRtuClient : creates
    IModbusTcpClient --|> IModbusClient
    IModbusRtuClient --|> IModbusClient
Loading

Class diagram for Modbus data types and operations

classDiagram
    class Coils {
        <<data type>>
        +ReadCoilsAsync()
        +WriteCoilAsync()
        +WriteMultipleCoilsAsync()
    }
    class DiscreteInputs {
        <<data type>>
        +ReadInputsAsync()
    }
    class InputRegisters {
        <<data type>>
        +ReadInputRegistersAsync()
    }
    class HoldingRegisters {
        <<data type>>
        +ReadHoldingRegistersAsync()
        +WriteRegisterAsync()
        +WriteMultipleRegistersAsync()
    }
    IModbusClient --> Coils
    IModbusClient --> DiscreteInputs
    IModbusClient --> InputRegisters
    IModbusClient --> HoldingRegisters
Loading

File-Level Changes

Change Details Files
Replaced low-level socket demo with high-level ModbusFactory usage documentation
  • Removed raw ITcpSocketClient code snippet
  • Added descriptive paragraphs and a code-label heading for client creation
  • Streamlined markup under section 3
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
Introduced Modbus protocol variant overview
  • Added list entries for Modbus RTU and Modbus TCP/IP with details on physical layers and framing
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
Documented ModbusFactory methods for obtaining and removing clients
  • Listed GetOrCreateTcpMaster/UdpMaster/RtuMaster/RtuOverTcpMaster/RtuOverUdpMaster
  • Added example for RemoveTcpMaster
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
Added data operation section for IModbusClient methods
  • Introduced code-label heading for data operations
  • Enumerated Read/Write methods for coils, discrete inputs, input and holding registers
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
Cleaned up obsolete content and formatting
  • Removed data package/adapter section
  • Fixed whitespace in ModbusFactories.razor.cs
  • Updated project/docs configuration placeholders
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor.cs
src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
src/BootstrapBlazor.Server/docs.json

Assessment against linked issues

Issue Objective Addressed Explanation
#6721 Add documentation for ModbusFactory, including sample code.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 8ebcb45 into main Sep 7, 2025
4 checks passed
@ArgoZhang ArgoZhang deleted the doc-modbus branch September 7, 2025 11:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds documentation for the ModbusFactory component, providing comprehensive guidance on Modbus protocol implementation and usage. The changes focus on replacing generic TCP socket documentation with specific Modbus communication examples and explanations.

  • Adds new documentation page for ModbusFactory with detailed Modbus protocol coverage
  • Updates package versions for Longbow.Modbus and Longbow.TcpSocket
  • Registers the new ModbusFactory documentation in the docs navigation

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
docs.json Adds routing entry for the new ModbusFactory documentation page
ModbusFactories.razor Replaces TCP socket documentation with comprehensive Modbus protocol documentation covering RTU, TCP/IP variants and data operations
BootstrapBlazor.Server.csproj Updates Longbow.Modbus from 9.0.0 to 9.0.2 and Longbow.TcpSocket from 9.0.3 to 9.0.4

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

<li><b>粘包</b>比如我们期望收到 <b>1234</b> 四个字符,实际上我们接收到的是 <b>123412</b> 多出来的 <b>12</b> 其实是下一个数据包的内容,我们需要截取前 4 位数据作为一个数据包才能正确处理数据,这种相邻两个通讯数据包的粘连称为<b>粘包</b></li>
<li><b>分包</b>比如我们期望收到 <b>1234</b> 四个字符,实际上我们可能分两次接收到,分别是 <b>12</b><b>34</b>,我们需要将两个数据包拼接成一个才能正确的处理数据。这种情况称为<b>分包</b></li>
<li>通过 <code>GetOrCreateTcpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetOrCreateUdpMaster method should return IModbusUdpClient, not IModbusTcpClient. UDP and TCP are different protocols and should have distinct client types.

Suggested change
<li>通过 <code>GetOrCreateUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateUdpMaster</code> 方法得到 <code>IModbusUdpClient</code> 实例</li>

Copilot uses AI. Check for mistakes.
<li>通过 <code>GetOrCreateUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuMaster</code> 方法得到 <code>IModbusRtuClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuOverTcpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetOrCreateRtuOverUdpMaster method should return IModbusUdpClient, not IModbusTcpClient. This method uses UDP protocol and should have the corresponding client type.

Suggested change
<li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusUdpClient</code> 实例</li>

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +36
<li>通过 <code>GetOrCreateRtuMaster</code> 方法得到 <code>IModbusRtuClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuOverTcpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
<li>通过 <code>GetOrCreateRtuOverUdpMaster</code> 方法得到 <code>IModbusTcpClient</code> 实例</li>
Copy link

Copilot AI Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation using tabs instead of spaces. The first line uses spaces while lines 35-36 use tabs. This should be consistent throughout the file.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The ModbusFactories.razor.cs file is empty except for whitespace—either remove it or add the intended logic to avoid orphaned partial classes.
  • Double-check that GetOrCreateUdpMaster and GetOrCreateRtuOverUdpMaster return the correct UDP client interface rather than IModbusTcpClient for clearer API semantics.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The ModbusFactories.razor.cs file is empty except for whitespace—either remove it or add the intended logic to avoid orphaned partial classes.
- Double-check that GetOrCreateUdpMaster and GetOrCreateRtuOverUdpMaster return the correct UDP client interface rather than IModbusTcpClient for clearer API semantics.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (280fec1) to head (04242fb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6722   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31713     31713           
  Branches      4462      4462           
=========================================
  Hits         31713     31713           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(Modbu): add ModbusFactory documentation

2 participants